﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;

public partial class _default : System.Web.UI.Page
{
    public string TourTrongNuoc = ConfigurationSettings.AppSettings["TourTrongNuoc"].Replace("+", "&");
    public string TourNuocNgoai = ConfigurationSettings.AppSettings["TourNuocNgoai"].Replace("+", "&");
    public string KinhNghiemDuLich = ConfigurationSettings.AppSettings["KinhNghiemDuLich"].Replace("+", "&");
    public string AnhDepDuLich = ConfigurationSettings.AppSettings["AnhDepDuLich"].Replace("+", "&");
    public string AmThucDuLich = ConfigurationSettings.AppSettings["AmThucDuLich"].Replace("+", "&");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadComboKh();
            LoadComboDd();
        }
    }
    public string HtmlWriteTourKhuyenMai()
    {
        string htmlCode = "";
        DataTable dtTour = DataAccess.ExeSQLToDataTable("SELECT TOP(4) * FROM dev_news WHERE khuyenmai = 1 ORDER BY idnews DESC");

        if (dtTour == null || dtTour.Rows.Count == 0)
        {
            dtTour = DataAccess.ExeSQLToDataTable("SELECT TOP(4) * FROM dev_news WHERE checktour = 1 ORDER BY idnews DESC");
        }
        int tCount = dtTour.Rows.Count;

        if (tCount > 0)
        {
            htmlCode += "<div class=\"div_titlebar\"><a href='/tourdulich.aspx" + dtTour.Rows[0]["link_web"]
                     + "' title='Chùm tour du lịch khuyến mại'><p class=\"p_tilebar_all\">Chùm tour hot - tour khuyến mại</p></a></div>";
            int count = 0;
            string strScriptCounter = "<script>CountDownTimer('{0}', '{1}');</script>";
            foreach (DataRow item in dtTour.Rows)
            {
                string strUrl = "chitiettourdulich.aspx?id=" + item["idnews"];
                string strUrlDatTour = "dattourdulich.aspx?id=" + item["idnews"];
                string strTitle = item["title"].ToString().Length < 70 ? item["title"].ToString() : item["title"].ToString().Substring(0, 70) + "...";
                string strPicLink = "/files_upload/images/pictour/" + item["picture"];
                string strTourTime = item["thoigian"].ToString();
                string strDes = item["sapo"].ToString().Length > 150 ? item["sapo"].ToString().Substring(0, 150) + "..." : item["sapo"].ToString();
                string strTietKiem = item["tietkiem"].ToString();
                string[] arr_date = item["thoigiandattour"].ToString().Split('/');
                string strThoiDatTour = arr_date[1] + "/" + arr_date[0] + "/" + arr_date[2] + " 00:00 AM";
                string strGiaMoi = item["giatourmoi"].ToString();
                string strGiaCu = item["giatour"].ToString();

                htmlCode += "<div class=\"div_item_tourhot\">";
                htmlCode += "<a href=\"" + strUrl + "\" title='" + strTitle + "'><p class=\"p_tourhot_title\">" + strTitle + "</p></a>";
                htmlCode += "<a href=\"" + strUrl + "\" title='" + strTitle + "'><img alt=\"" + strTitle + "\" class=\"img_tourhot_pic\" src=\"" + strPicLink + "\" /></a>";
                htmlCode += "<p class='p_thoigian'> <b>Thời gian:</b>" + formatngay(strTourTime) + "</p>";
                htmlCode += "<a class=\"a_descriptions\">" + strDes + "</a>";
                htmlCode += "<div class=\"div_thongtingia\">";
                htmlCode += "<a class=\"a_dattuor\" href='" + strUrlDatTour + "'>Đặt Tour</a>";
                htmlCode += "<div class=\"div_tietkiem\"><a class=\"a_giamgia\">" + strTietKiem + "%</a> tiết kiệm</div>";
                htmlCode += String.Format(strScriptCounter, strThoiDatTour, "timercounter_" + count);
                htmlCode += "<div class=\"div_tietkiem div_songay\"><a class=\"a_giamgia\" id='timercounter_" + count + "'></a> thời gian còn lại</div>";
                htmlCode += "<div class=\"div_giatour\">";
                htmlCode += "<p class=\"p_gia\">Giá mới:<a class=\"a_gia\">" + (String.Format("{0:0,0}", item["giatourmoi"])) + " VNĐ</a></p>";
                htmlCode += "<p class=\"p_gia\">Giá cũ:<a class=\"a_gia a_gia_cu\">" + (String.Format("{0:0,0}", item["giatour"])) + " VNĐ</a></p>";
                htmlCode += "</div>";
                htmlCode += "</div>";
                htmlCode += "</div>";

                count++;
            }
        }

        return htmlCode;
    }
    public string formatngay(string idngay)
    {
        string html = "";
        DataTable dt = DataAccess.ExeSQLToDataTable("select * from Ngay where idDuLich='" + idngay + "'");
        if (dt.Rows.Count > 0)
        {
            html += " " + dt.Rows[0][1].ToString();
        }
        return html;
    }
    public string HtmlWriteLoaiTour(string link_web)
    {
        string htmlCode = "";
        DataTable dtTour = DataAccess.ExeSQLToDataTable("SELECT TOP(9) dev_news.*,Ngay.IdDuLich,Ngay.Name as 'Ngay' FROM dev_news,Ngay WHERE checktour = 1 AND link_web = '" + link_web + "' and Ngay.IdDuLich=dev_news.thoigian  ORDER BY idnews DESC");
        int tCount = dtTour.Rows.Count;
        if (tCount > 0)
        {
            foreach (DataRow item in dtTour.Rows)
            {
                string s = item["thoigian"].ToString();
            }
            //Bon tour moi nhat
            int dem = 0;
            foreach (DataRow item in dtTour.Rows)
            {
                string strUrl = "chitiettourdulich.aspx?id=" + item["idnews"];
                string strTitle = item["title"].ToString().Length < 50 ? item["title"].ToString() : item["title"].ToString().Substring(0, 50) + "...";
                string strPicLink = "/files_upload/images/pictour/" + item["picture"];
                string strTourTime = item["Ngay"].ToString();
                string strGiaMoi = item["giatourmoi"].ToString();

                htmlCode += "<div class=\"item_tourdulich\">";
                htmlCode += "<a href=\"" + strUrl + "\" title='" + strTitle + "'><p class=\"p_title\">" + strTitle + "</p></a>";
                htmlCode += "<a href=\"" + strUrl + "\"><img alt=\"" + strTitle + "\" class=\"img_tour_pic\" src=\"" + strPicLink + "\" /></a>";
                htmlCode += "<div class=\"div_thongtin\"><p class=\"p_thongtin\"> <b>Thời gian: </b><a>" + strTourTime
                         + "</a></p><p class=\"p_thongtin\"><b>Giá tour: <a style=\"color: Red;\">" + (String.Format("{0:0,0}", item["giatourmoi"])) + " VNĐ</a></b></p></div>";
                htmlCode += "</div>";

                dem++;
                if (dem == 4) break;
            }

            //Lay top 5 ben duoi
            if (tCount > 4)
            {
                htmlCode += "<div><ul class=\"ul_list_tour\">";
                for (int i = 4; i < tCount; i++)
                {
                    string strUrl = "chitiettourdulich.aspx?id=" + dtTour.Rows[i]["idnews"];
                    string strTitleAlt = dtTour.Rows[i]["title"].ToString();
                    string strTitle = dtTour.Rows[i]["title"].ToString().Length < 40 ? dtTour.Rows[i]["title"].ToString() : dtTour.Rows[i]["title"].ToString().Substring(0, 40) + "...";
                    string strPicLink = "/files_upload/images/news/" + dtTour.Rows[i]["picture"];
                    string strGiaMoi = dtTour.Rows[i]["giatour"].ToString();

                    htmlCode += "<li><a href=\"" + strUrl + "\" class=\"a_title_tour\" title='" + strTitleAlt + "'>" + strTitle
                             + "</a><a class=\"a_giatour\">Giá tour: " + ((String.Format("{0:0,0}", dtTour.Rows[i]["giatour"]))) + " VNĐ</a></li>";
                }
                htmlCode += "</ul></div>";
            }
            htmlCode += "<a class=\"a_xemthem\" href='tourdulich.aspx" + dtTour.Rows[0]["link_web"]
                     + "' title='Xem thêm tour du lịch'>Xem thêm</a>";
        }

        return htmlCode;
    }
  protected string  GetNameDiaDiemById(long id)
    {
        DataTable dt = DataAccess.ExeSQLToDataTable("select Name from DiaDanh where IdYahoo = '" + id + "'");
        if (dt.Rows.Count == 0)
        {
            return "";
        }
        else
        {
            return dt.Rows[0][0] == null ? "" : dt.Rows[0][0].ToString();
        }

    }
    public string video()
    {
        string html = "";
        DataTable dtvideo = DataAccess.ExeSQLToDataTable("select top(1)* from video");
        html += dtvideo.Rows[0][1].ToString();
        return html;

    }
    public string HtmlWriteVeMayBay()
    {
        string htmlCode = "";
        DataTable dtTour = DataAccess.ExeSQLToDataTable("SELECT TOP(6) * FROM dev_news WHERE vemaybay = 1 ORDER BY idnews DESC");
        int tCount = dtTour.Rows.Count;
        if (tCount > 0)
        {
            htmlCode += "<div class='div_titlebar'><a href='/vemaybay.aspx" + dtTour.Rows[0]["link_web"]
                     + "' title='Vé máy bay'><p class='p_tilebar_all'>Vé máy bay</p></a></div>";
            foreach (DataRow item in dtTour.Rows)
            {
                string strUrl = "/chitietvemaybay.aspx?id=" + item["idnews"];
                string strTitle = item["title"].ToString().Length < 50 ? item["title"].ToString() : item["title"].ToString().Substring(0, 50) + "...";
                string strTitleAlt = item["title"].ToString();

                htmlCode += "<div class='item_vemaybay'>";
                htmlCode += "<a href='" + strUrl + "' title='" + strTitleAlt + "'><p class='p_title_vemaybay'>" + strTitle + "</p></a>";
                htmlCode += "<a href='" + strUrl + "' title='" + strTitleAlt + "'><img alt='" + strTitleAlt + "' class='img_vemaybay_pic' src='/files_upload/images/vemaybay/" + item["picture"] + "' /></a>";
                htmlCode += "<p class='p_thongtinve'><b>Xuất phát: </b><a>" + (GetNameDiaDiemById(Convert.ToInt32(item["diemxuatphat"]))) + "</a></p><p class='p_thongtinve'><b>Điểm đến: </b><a>" + (GetNameDiaDiemById(Convert.ToInt32(item["diemden"]))) + "</a></p>";
                htmlCode += "<p class='p_thongtinve'><b>Giá vé: <a style='color: Red;'>Liên hệ</a></b></p><a href='/datvemaybay.aspx?idve=" + item["idnews"] + "' class='a_datve'>Đặt vé</a>";
                htmlCode += "</div>";
            }
        }

        return htmlCode;
    }

    public string HtmlWriteTinTucThree(string link_web)
    {
        string htmlCode = "<ul class=\"ul_list_tintuc_dulich_khac\">";
        DataTable dtTour = DataAccess.ExeSQLToDataTable("SELECT TOP(6) * FROM dev_news WHERE link_web = '" + link_web + "' ORDER BY idnews DESC");
        int tCount = dtTour.Rows.Count;
        if (tCount > 0)
        {
            foreach (DataRow item in dtTour.Rows)
            {
                htmlCode += "<li><a href='/chitiettin.aspx?idnews=" + item["idnews"] + "' title='" + item["title"]
                    + "'>" + (item["title"].ToString().Length < 45 ? item["title"].ToString() : item["title"].ToString().Substring(0, 45) + "...") + "</a></li>";
            }
            htmlCode += "</ul><a href=\"/tintuc.aspx" + dtTour.Rows[0]["link_web"] + "\" class=\"a_xemthem\">Xem thêm</a>";
        }

        return htmlCode;
    }

    public string HtmlWriteSlider()
    {
        string htmlCode = "";
        DataTable dtTour = DataAccess.ExeSQLToDataTable("SELECT TOP(10) * FROM banner WHERE ViTri = 4 ORDER BY IdQC DESC");
        int tCount = dtTour.Rows.Count;
        if (tCount > 0)
        {
            foreach (DataRow item in dtTour.Rows)
            {
                htmlCode += "<li style=\"float: left;\"><a href=\"" + item["Link"] + "\"><img alt=\"" + item["Name"]
                         + "\" src=\"/files_upload/images/quangcao/" + item["Image"] + "\" /></a></li>";
            }
        }

        return htmlCode;
    }
    protected string GetYahooDl()
    {
        string htmlCode = "";
        DataTable tbl = DataAccess.ExeSQLToDataTable("select top(2) * from Yahoo where Check_Skype_Yahoo=1 and Check_DuLich_VeMB=11 and status =1  order by IdYahoo desc");

        if (tbl.Rows.Count > 0)
        {
            foreach (DataRow dr in tbl.Rows)
            {
                htmlCode += @"<a href='ymsgr:sendim?" + dr["Nick"] + @"' style='text-decoration: none;' title='Y!M: " + dr["Nick"] + @"'>
                                <img class='div-imgYM' alt=''
                                    src='http://opi.yahoo.com/online?u=" + dr["Nick"] + @"&m=g&t=1' border='0' title='Y!M: " + dr["Nick"] + @"'>
                            </a>";
            }
        }
        return htmlCode;
    }
    protected string GetYahooVeMB()
    {
        string htmlCode = "";
        DataTable tbl = DataAccess.ExeSQLToDataTable("select top(2) * from Yahoo where Check_Skype_Yahoo=1 and Check_DuLich_VeMB=22 and status =1  order by IdYahoo desc");

        if (tbl.Rows.Count > 0)
        {
            foreach (DataRow dr in tbl.Rows)
            {
                htmlCode += @"<a href='ymsgr:sendim?" + dr["Nick"] + @"' style='text-decoration: none;' title='Y!M: " + dr["Nick"] + @"'>
                                <img class='div-imgYM' alt=''
                                    src='http://opi.yahoo.com/online?u=" + dr["Nick"] + @"&m=g&t=1' border='0' title='Y!M: " + dr["Nick"] + @"'>
                            </a>";
            }
        }
        return htmlCode;
    }
    protected string GetSkypeDl()
    {
        string htmlCode = "";
        DataTable tbl = DataAccess.ExeSQLToDataTable("select top(1) * from Yahoo where Check_Skype_Yahoo=2 and Check_DuLich_VeMB=33 and status =1  order by IdYahoo desc");

        if (tbl.Rows.Count > 0)
        {
            foreach (DataRow dr in tbl.Rows)
            {
                htmlCode += @"<div id='SkypeButton_Dropdown_" + dr["Nick"] + @"_1'>
                                <script type='text/javascript'>
                                    Skype.ui({
                                            'name': 'dropdown',
                                            'element': 'SkypeButton_Dropdown_" + dr["Nick"] + @"_1',
                                            'participants': ['" + dr["Nick"] + @"']
                                        });
                                </script>
                            </div>";
            }
        }
        return htmlCode;
    }
    protected string GetSkypeVeMB()
    {
        string htmlCode = "";
        DataTable tbl = DataAccess.ExeSQLToDataTable("select top(1) * from Yahoo where Check_Skype_Yahoo=2 and Check_DuLich_VeMB=44 and status =1  order by IdYahoo desc");

        if (tbl.Rows.Count > 0)
        {
            foreach (DataRow dr in tbl.Rows)
            {
                htmlCode += @"<div id='SkypeButton_Dropdown_" + dr["Nick"] + @"_1'>
                                <script type='text/javascript'>
                                    Skype.ui({
                                            'name': 'dropdown',
                                            'element': 'SkypeButton_Dropdown_" + dr["Nick"] + @"_1',
                                            'participants': ['" + dr["Nick"] + @"']
                                        });
                                </script>
                            </div>";
            }
        }
        return htmlCode;
    }
    protected string GetHotLine()
    {
        string htmlCode = "";
        DataTable tbl = DataAccess.ExeSQLToDataTable("select top(1) * from Yahoo where Check_Hotline = 3 and status =1  order by IdYahoo desc");

        if (tbl.Rows.Count > 0)
        {
            foreach (DataRow dr in tbl.Rows)
            {
                htmlCode += @"<a class='titleHotline'>Hotline</a><a class='phoneHotline'>" + dr["Name"] + @"</a>";
            }
        }
        return htmlCode;
    }
    protected void LoadComboKh()
    {
        string linkweb = "?menu=175&parent=173";
        DataTable dt = DataAccess.ExeSQLToDataTable("select * from DiaDanh where CheckTour='" + linkweb + "'");
        if (dt.Rows.Count > 0)
        {
            selectKh.DataSource = dt;
            selectKh.DataTextField = "Name";
            selectKh.DataValueField = "IdYahoo";
            selectKh.DataBind();
        }
    }
    protected void CheckTour(object sender, EventArgs e)
    {
        string linkweb = "";
        linkweb = "?menu=175&parent=173";
        DataTable dt = DataAccess.ExeSQLToDataTable("select * from DiaDanh where CheckTour='" + linkweb + "'");
        if (dt.Rows.Count > 0)
        {
            selectDd.DataSource = dt;
            selectDd.DataTextField = "Name";
            selectDd.DataValueField = "IdYahoo";
            selectDd.DataBind();
        }
    }
    protected void LoadComboDd()
    {
        string linkweb = "";
        linkweb = "?menu=175&parent=173";
        DataTable dt = DataAccess.ExeSQLToDataTable("select * from DiaDanh where CheckTour='" + linkweb + "'");
        if (dt.Rows.Count > 0)
        {
            selectDd.DataSource = dt;
            selectDd.DataTextField = "Name";
            selectDd.DataValueField = "IdYahoo";
            selectDd.DataBind();
        }
    }
    protected void TimKiemClick(object sender, EventArgs e)
    {
        long idkhoihanh = Convert.ToInt64(selectKh.SelectedValue);
        long iddiemden = Convert.ToInt64(selectDd.SelectedValue);
        Response.Redirect("timkiemtourdulich.aspx?idkhoihanh=" + idkhoihanh + "&iddiemden=" + iddiemden);
    }
    protected void ChangeOpt(object sender, EventArgs e)
    {
        if (rbSearch.SelectedValue == "2")
        {
            string linkweb = "";
            linkweb = "?menu=174&parent=173";
            DataTable dt = DataAccess.ExeSQLToDataTable("select * from DiaDanh where CheckTour='" + linkweb + "'");
            if (dt.Rows.Count > 0)
            {
                selectDd.DataSource = dt;
                selectDd.DataTextField = "Name";
                selectDd.DataValueField = "IdYahoo";
                selectDd.DataBind();
            }
        }
        if (rbSearch.SelectedValue == "1")
        {
            string linkweb = "";
            linkweb = "?menu=175&parent=173";
            DataTable dt = DataAccess.ExeSQLToDataTable("select * from DiaDanh where CheckTour='" + linkweb + "'");
            if (dt.Rows.Count > 0)
            {
                selectDd.DataSource = dt;
                selectDd.DataTextField = "Name";
                selectDd.DataValueField = "IdYahoo";
                selectDd.DataBind();
            }
        }
    }
}